package com.leetcode.LeetCode精选TOP面试题;

/**
 * @author 覃国强
 * @date 2022-06-21 18:29
 */
public class 题库_0125_验证回文串 {

  static
  class Solution {
    public boolean isPalindrome(String s) {
      if (s == null || s.length() == 0) {
        return true;
      }
      int left = 0;
      int right = s.length() - 1;
      while (left < right) {
        while (left < right && !Character.isDigit(s.charAt(left)) && !Character.isLetter(s.charAt(left))) {
          ++left;
        }
        while (left < right && !Character.isDigit(s.charAt(right)) && !Character.isLetter(s.charAt(right))) {
          --right;
        }
        if (left < right && Character.toLowerCase(s.charAt(left)) != Character.toLowerCase(s.charAt(right))) {
          return false;
        }
        ++left;
        --right;
      }
      return true;
    }
  }

}
